//
//  PokemonDetailVC.swift
//  PokeMon-main
//
//  Created by Mainzxq on 16/7/18.
//  Copyright © 2016年 安爹的苹果机. All rights reserved.
//

import UIKit

class PokemonDetailVC: UIViewController {

    @IBOutlet weak var nameLbl: UILabel!
    var selectpoke: Pokemon!
    
    @IBOutlet weak var mainImage: UIImageView!
    @IBOutlet weak var descriptionLbl: UILabel!
    @IBOutlet weak var TypeLabel: UILabel!
    @IBOutlet weak var defenceLbl: UILabel!
    @IBOutlet weak var heightLbl: UILabel!
    @IBOutlet weak var pokedexLbl: UILabel!
    @IBOutlet weak var weightLbl: UILabel!
    @IBOutlet weak var attackLbl: UILabel!
    @IBOutlet weak var currentEvoImg: UIImageView!
    @IBOutlet weak var nextEvoImg: UIImageView!
    @IBOutlet weak var evoLbl: UILabel!
    
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //nextEvoImg.hidden = true

        
        selectpoke.downloadPokemonDetails { 
            print("我们结束了")
            self.updateUI()
        }
        nameLbl.text = selectpoke.name
        pokedexLbl.text = "\(selectpoke.pokedexId)"
        let img = UIImage(named: "\(selectpoke.pokedexId)")
        mainImage.image = img
        currentEvoImg.image = img
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func updateUI() {

        descriptionLbl.text = selectpoke.description
        TypeLabel.text = selectpoke.type
        defenceLbl.text = selectpoke.defense
        heightLbl.text = selectpoke.height
        weightLbl.text = selectpoke.weight
        
        if selectpoke.nextEvoId == "" {
            evoLbl.text = "No Evolutions"
            nextEvoImg.hidden = true
        } else {
            nextEvoImg.hidden = false
            nextEvoImg.image = UIImage(named: selectpoke.nextEvoId)
            var str = "Next Evolution:\(selectpoke.nextEvoTxt)"
            if selectpoke.nextEvoLvl != "" {
                str += "- LVL \(selectpoke.nextEvoLvl)"
            }
            evoLbl.text = str
        }

    }

    
    @IBAction func backBtnPressed(sender: AnyObject) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }

}
